﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace UI_Layer.Pages
{
    /// <summary>
    /// Interaction logic for BookingDetailsCreate.xaml
    /// </summary>
    public partial class BookingDetailsCreate : Page
    {
        public BookingDetailsCreate()
        {
            InitializeComponent();

            DispatcherTimer timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
            {
                this.BookingDetailsCreate_clock_label.Content = DateTime.Now.ToString("HH:mm:ss");
            }, this.Dispatcher); 

            Combobox_BookingTime.ItemsSource = LoadComboBoxData();
            
        }

        //Data Variables 

        private static string plateNumber;
        private static string bookedTime;
        private static int payAmount;

        private string bookedTime_Temp;

        public static string getPlateNumber
        {
            get { return plateNumber; }            
        }

        public static string getBookedTime
        {
            get { return bookedTime; }  
        }

        public static int getPayAmount
        {
            get { return payAmount; }
        }

        private string[] LoadComboBoxData()
        {
            string[] strArray =
            {
                "1 hour", "2 hours", "3 hours", "4 hours", "5 hours", "6 hours", "7 hours", "8 hours", "9 hours", "10 hours",
                "11 hours", "12 hours", "13 hours", "14 hours", "15 hours", "16 hours", "17 hours", "18 hours", "19 hours", 
                "20 hours", "21 hours", "22 hours", "23 hours", "24 hours"
            };
            return strArray;
        }

        private void ButtonClick_GoBack(object sender, RoutedEventArgs e)
        {
            NavigationService.GoBack();
        }
         

        private void ButtonClick_PayParking(object sender, RoutedEventArgs e)
        {            
            if (!String.IsNullOrEmpty(TextBox_PlateNumber.Text))
            {
                plateNumber = TextBox_PlateNumber.Text;
                bookedTime = bookedTime_Temp;
                PaymentOptions paymentoptions = new PaymentOptions();
                NavigationService navservice = NavigationService.GetNavigationService(this);
                navservice.Navigate(paymentoptions);                
            }
            else
            {
                MessageBox.Show("Insert Plate Number");                
            }
        }

        private void Combobox_BookingTime_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Button_ProceedBooking.Visibility = Visibility.Visible;
            int rate = 1;
            int hours_booked = 0;            
            
            try            {

                string value = this.Combobox_BookingTime.Items[this.Combobox_BookingTime.SelectedIndex].ToString();

                if (value.Contains("1 hour"))
                {
                    string value_new = value.Replace("hour", "");
                    bookedTime_Temp = value_new;
                    hours_booked = Convert.ToInt32(value_new);
                }

                else 
                {                
                    string value_new = value.Replace("hours", "");
                    bookedTime_Temp = value_new;
                    hours_booked = Convert.ToInt32(value_new);
                }

                payAmount = rate * hours_booked;
                Label_Cost.Content = rate * hours_booked + " RON";               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
